﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel.DataAnnotations;

namespace HelfenHelfen.RIA.Web.Models
{
    public class DescriptionValidation
    {
        public static ValidationResult IsValidDescription(string description, ValidationContext context)
        {
            var res = ValidationResult.Success;

            if (String.IsNullOrEmpty(description) || description.WordCount() < 3)
            {
                res = new ValidationResult("Description must contain at least 3 words!");
            }

            return res;

        }
    }

    #region "String extension Word count"

    public static class StringExtensions
    {
        public static int WordCount(this String str)
        {
            return str.Split(new char[] { ' ', '.', '?', '!' }, StringSplitOptions.RemoveEmptyEntries).Length;
        }
    }

    #endregion
}